home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / OWLINC.PAK / WSKSOCKD.H < prev    next >
C/C++ Source or Header  |  1997-05-06  |  4KB  |  137 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // Copyright (c) 1995, 1997 by Borland International, All Rights Reserved
  4. //
  5. //$Revision:   10.10  $
  6. //
  7. // Winsock for OWL subsystem.
  8. // Based on work by Paul Pedriana, 70541.3223@compuserve.com
  9. //----------------------------------------------------------------------------
  10. #if !defined(OWL_WSKSOCKD_H)
  11. #define OWL_WSKSOCKD_H
  12.  
  13. #if !defined(OWL_WINSOCK_H)
  14. # include <owl/wsksock.h>
  15. #endif
  16.  
  17. #if defined(BI_NAMESPACE)
  18. namespace OWL {
  19. #endif
  20.  
  21. // Generic definitions/compiler options (eg. alignment) preceeding the 
  22. // definition of classes
  23. #include <services/preclass.h>
  24.  
  25. //
  26. // class TDatagramSocket
  27. // ~~~~~ ~~~~~~~~~~~~~~~
  28. // TDatagramSocket encapsulates a Winsock datagram socket.
  29. // NOTE: Unlike stream sockets, datagram sockets are unreliable - i.e. the 
  30. //       bi-directional flow of data is not guaranteed to be sequenced and/or 
  31. //       unduplicated.
  32. //
  33. class _OWLCLASS TDatagramSocket : public TSocket {
  34.   public:
  35.     TDatagramSocket();
  36.     TDatagramSocket(SOCKET& newS);
  37.     TDatagramSocket(TSocketAddress& newSocketAddress, int addressFormat = PF_INET,
  38.                     int type = SOCK_DGRAM, int protocol = 0);
  39.     TDatagramSocket& operator =(TDatagramSocket& newDatagramSocket1);
  40.  
  41.     void SetMaxPacketSendSize(int size);
  42.     int Read(char* data, int& charsToRead, TSocketAddress& sAddress);
  43.     int Write(char* data, int& charsToWrite, TSocketAddress& outSocketAddress,
  44.               bool becomeOwnerOfData = true, bool copyData = true);
  45.     int Write(char* data, int& charsToWrite, bool becomeOwnerOfData = true,
  46.               bool copyData = true);
  47.  
  48.   protected:
  49.     //Defined by the WSAStartup() call return information (WSAData).
  50.     //
  51.     static int MaxPacketSendSize;
  52.  
  53.     DoReadNotification(const SOCKET& s, int error);
  54.     DoWriteNotification(const SOCKET& s, int error);
  55. };
  56.  
  57. #define N_DEF_MAX_QUEUED_CONNECTIONS 5
  58.  
  59. //
  60. // class TStreamSocket
  61. // ~~~~~ ~~~~~~~~~~~~~
  62. // The StreamSocket encapsulates a Winsock stream socket.
  63. //
  64. class _OWLCLASS TStreamSocket : public TSocket {
  65.   public:
  66.     // Current status of this stream socket
  67.     //
  68.     enum TConnectStatus {
  69.       NotConnected,       // This socket is not used
  70.       ConnectPending,     // Connection is pending
  71.       Connected,          // Currently connected
  72.       Listening           // Waiting for a connection
  73.     } ConnectStatus;
  74.  
  75.     TStreamSocket();
  76.     TStreamSocket(SOCKET& newS);
  77.     TStreamSocket(TSocketAddress& socketAddress, int addressFormat = PF_INET,
  78.                   int Type = SOCK_STREAM, int protocol = 0);
  79.     TStreamSocket& operator =(TStreamSocket& src);
  80.  
  81.     int Listen(int nMaxQueuedConnections = N_DEF_MAX_QUEUED_CONNECTIONS);
  82.     int Connect();
  83.     int Connect(TSocketAddress& addressToConnectTo);
  84.     int Accept(TStreamSocket& socket);
  85.     int Accept(SOCKET& socket, sockaddr& sAddress);
  86.  
  87.     int Read(char* data, int& charsToRead);
  88.     int Write(char* data, int& charsToWrite, int flags = 0,
  89.               bool becomeOwnerOfData = true, bool copyData = true);
  90.               //Is the same as send func
  91.     int ReadOOB(char* data, int& charsToRead);
  92.     int WriteOOB(char* data, int& charsToWrite, int nFlags = MSG_OOB,
  93.                  bool becomeOwnerOfData = true, bool copyData = true);
  94.                  //ORs nFlags w MSG_OOB.
  95.  
  96.   protected:
  97.     DoReadNotification(const SOCKET& s, int nError);
  98.     DoWriteNotification(const SOCKET& s, int nError);
  99.     DoOOBNotification(const SOCKET& s, int nError);
  100.     DoAcceptNotification(const SOCKET& s, int nError);
  101.     DoConnectNotification(const SOCKET& s, int nError);
  102.     DoCloseNotification(const SOCKET& s, int nError);
  103. };
  104.  
  105. // Generic definitions/compiler options (eg. alignment) following the 
  106. // definition of classes
  107. #include <services/posclass.h>
  108.  
  109. #if defined(BI_NAMESPACE)
  110. } // namespace OWL
  111. #endif
  112.  
  113. //----------------------------------------------------------------------------
  114. // Inline implementations
  115. //
  116.  
  117. //
  118. // Copies the datagram socket connection information.
  119. //
  120. inline TDatagramSocket&
  121. TDatagramSocket::operator =(TDatagramSocket& newDatagramSocket1)
  122. {
  123.   TSocket::operator =(newDatagramSocket1);
  124.   return *this;
  125. }
  126.  
  127. //
  128. // Set the maximum size of the send packet buffer.
  129. //
  130. inline void
  131. TDatagramSocket::SetMaxPacketSendSize(int size)
  132. {
  133.   MaxPacketSendSize = size;
  134. }
  135.  
  136. #endif  // OWL_WSKSOCKD_H
  137.